package com.example.controller;

import com.example.entity.MyResponseEntity;
import com.example.entity.Team;
import com.example.entity.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author fyx
 */
@RestController
@RequestMapping("/json")
public class JsonController {
    @RequestMapping(value = "/json2User", produces = "application/json;charset=utf-8")
    public MyResponseEntity<User> jsonUser(@RequestBody User user) {
        return MyResponseEntity.creat(200, "请求成功", user);
    }

    @RequestMapping(value = "/json2Arr", produces = "application/json;charset=utf-8")
    public MyResponseEntity<int[]> jsonArr(@RequestBody int[] arr) {
        return MyResponseEntity.creat(200, "请求成功", arr);
    }

    @RequestMapping(value = "/json2List", produces = "application/json;charset=utf-8")
    public MyResponseEntity<List<String>> jsonList(@RequestBody List<String> list) {
        return MyResponseEntity.creat(200, "请求成功", list);
    }

    @RequestMapping(value = "/json2Map", produces = "application/json;charset=utf-8")
    public MyResponseEntity<Map<String, String>> json2Map(@RequestBody Map<String, String> map) {
        return MyResponseEntity.creat(200, "请求成功", map);
    }

    @RequestMapping(value = "/json2Users", produces = "application/json;charset=utf-8")
    public MyResponseEntity<List<User>> json2List(@RequestBody List<User> users) {
        return MyResponseEntity.creat(200, "请求成功", users);
    }

    @RequestMapping(value = "/json2Team", produces = "application/json;charset=utf-8")
    public MyResponseEntity<Team> json2Team(@RequestBody Team team) {
        return MyResponseEntity.creat(200, "请求成功", team);
    }

    @RequestMapping(value = "/test", produces = "application/json;charset=utf-8")
    public MyResponseEntity<String> testInterceptor() {
        System.out.println("JsonController.testInterceptor");
        return new MyResponseEntity<>(200, "请求成功", "success");
    }
}
